 package telas;

 import java.util.Timer;
 import java.util.TimerTask;

 import javax.microedition.lcdui.Canvas;
 import javax.microedition.lcdui.Display;
 import javax.microedition.lcdui.Displayable;
 import javax.microedition.lcdui.Graphics;
 import javax.microedition.lcdui.Image;

 /**
  * Classe responsavel por construir e exibir a tela de
  * inicialização da aplicação
  *
  */
 public class SplashScreen extends Canvas {  
     private Display     display;
     private Displayable next;
     private Timer       timer = new Timer();
     private Image image;

     public SplashScreen(Display display, Displayable next ){

        System.out.println("splash");

        this.display = display;
         this.next = next;

         display.setCurrent(this);
     }

     protected void keyPressed( int keyCode ){
         dismiss();                                 //encerra qdo pressiona botao
     }

     protected void paint( Graphics g ){
        try{
           image = Image.createImage( "/imagemSplash.png" );
         }catch (Exception e) { }

        g.setColor(255,255,255);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.drawImage(image, getWidth()/2, getHeight()/2,Graphics.HCENTER|Graphics.VCENTER);

     }

     protected void pointerPressed( int x, int y ){
         dismiss();                                 //encerra qdo toca tela (em caso de dispositivo touchscreen)
     }

     protected void showNotify(){
         timer.schedule( new CountDown(), 3000 );  //depois do tempo determinado é chamado o metodo run()
     }

     private void dismiss(){
         timer.cancel();
         display.setCurrent( next );
     }

     private class CountDown extends TimerTask {
         public void run(){                           //encerra qdo acaba o tempo
             dismiss();
         }
     }
 }